#ifndef COMMAND_H
#define COMMAND_H
#pragma  once

#include <QMutex>
#include <QQueue>
#include <QImage>
#include <QFile>
#include <QWidget>
#include <QDebug>

class FrameQueue {
public:
    void enqueue(const QImage& frame) {
        QMutexLocker locker(&m_mutex);
        // 限制队列大小防止内存溢出
        if (m_queue.size() > MAX_FRAMES) {
            m_queue.dequeue();
        }
        m_queue.enqueue(frame);
    }

    QImage dequeue() {
        QMutexLocker locker(&m_mutex);
        if (m_queue.isEmpty()) {
            return QImage();
        }
        return m_queue.dequeue();
    }

    bool isEmpty() const {
        QMutexLocker locker(&m_mutex);
        return m_queue.isEmpty();
    }

private:
    static const int MAX_FRAMES = 10; // 最多缓存帧
    QQueue<QImage> m_queue;
    mutable QMutex m_mutex;
};

class LoadQss
{
public:
    void loadStyleSheet(QWidget* widget, const QString& fileName) {
        QFile file(fileName);
        if (file.open(QFile::ReadOnly)) {
            QString styleSheet = QLatin1String(file.readAll());
            widget->setStyleSheet(styleSheet);
            file.close();
        } else {
            qWarning() << "无法加载样式表文件:" << fileName;
        }
    }
};

#endif // COMMAND_H
